package GUI;
import java.io.File;

import Control.Character;
import processing.core.PImage;
public class IconButton extends Component
{
	////////////////////////////////////////////////////////////////////////////////////////////////////
	public boolean clicked;
	public boolean pressed;
	int x1InfoBox =0, x2InfoBox =0;
	Character c;

	////////////////////////////////////////////////////////////////////////////////////////////////////
	public IconButton()
	{
		width = Utils.BAR_ICON_WIDTH;
		height = Utils.BAR_ICON_HEIGHT;
		
	}
	public void setIcon(String name)
	{
		if(name != null)
		{
			icon = Utils.globalProcessing.loadImage(name);
			String var = name.substring(name.indexOf(File.separator)+1);
			c = Character.returnByShortName(Utils.characters, var.substring(0, var.indexOf('.')));
			x1InfoBox = x-(int)(Utils.globalProcessing.textWidth(c.getShortName()))-20;
			x2InfoBox = (int)(Utils.globalProcessing.textWidth(c.getShortName())) + 10;
		}
	}
	public void draw()
	{
		Utils.globalProcessing.textFont(Utils.plotFont, 12);

		clicked = false;
		int cx = x;
		int cy = y;
		if(mouseOver()) 
		{
			super.draw();
			if(Utils.globalProcessing.mousePressed)
			{
				pressed = true;
				cy+=2;
			}
			else if(pressed)
			{
				pressed = false;
				clicked = true;

				if(Utils.characterSelected.contains(c)){
					Utils.ccip.removeCharacterSelected(c);
				}
				else{
					Utils.ccip.addCharacterSelected(c);
				}
			}


		}
		else
		{
			pressed = false;
		}
		if(icon != null)
		{
			Utils.globalProcessing.image(icon, cx, cy,Utils.BAR_ICON_WIDTH,Utils.BAR_ICON_HEIGHT);
		}
		if(mouseOver()){
			drawInfoBox(x1InfoBox,y,x2InfoBox,c.getShortName());

		}
	}

	public void drawInfoBox(int x,int y,int width, String label){
		Utils.globalProcessing.textFont(Utils.plotFont, 12);
		Utils.globalProcessing.rectMode(Utils.globalProcessing.CORNER);
		Utils.globalProcessing.fill(200);
		Utils.globalProcessing.stroke(80);
		Utils.globalProcessing.strokeWeight(1);
		Utils.globalProcessing.rect(x+120, y+height-30, width, 30);

		Utils.globalProcessing.fill(0);
		//Utils.globalProcessing.textFont(Utils.globalProcessing.plotFont, 14);
		Utils.globalProcessing.textAlign(Utils.globalProcessing.LEFT);
		Utils.globalProcessing.text(label, x + 125, y - 10 +height);
	}


	////////////////////////////////////////////////////////////////////////////////////////////////////
	PImage icon;
}